package tagging;

import java.io.*;
import java.util.Vector;

public class TestSet extends Parser {
  FileWriter fw_;
  BufferedWriter out_;

  public TestSet(String fileName) throws Parser.ParserException, IOException {
    super(fileName, false);
    
    fw_ = new FileWriter(fileName + ".out");
    out_ = new BufferedWriter(fw_);
  }
  
  public void process(TrainingSet ts) throws Parser.ParserException, IOException {
    ViterbiProcessor vp = new ViterbiProcessor(ts);
    Vector<Parser.ProcessedWord> pwords = new Vector<Parser.ProcessedWord>();
    
    while (parseNextSentence(pwords)) {
      vp.process(pwords);
      writeProcessedWords(pwords);
    }
    
    out_.close();
    fw_.close();
  }
  
  public void writeProcessedWords(Vector<ProcessedWord> pwords) throws IOException {
    for (int i = 0; i < pwords.size(); ++i) {
      String line = pwords.get(i).getTag() + " " + pwords.get(i).getOriginalWord();
      if (pwords.get(i).isUnknown()) {
        line += " unknown";
      }
      if (Character.isUpperCase(pwords.get(i).getOriginalWord().charAt(0))) {
        line += " capitalized";
      }
        
      line += "\n";
      out_.write(line);
    }
  }
}
